package org.fu.crowd.service.impl;

import org.fu.crowd.entity.Auth;
import org.fu.crowd.mapper.AuthMapper;
import org.fu.crowd.service.api.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private AuthMapper authMapper;



    /**
     * 获取所有auth
     */
    @Override
    public List<Auth> getAllAuth() {
        return authMapper.selectByExample(null);
    }





    /**
     * 根据id查询角色可以使用的权利
     * @param roleId
     * @return
     */
    @Override
    public List<Integer> getAssigned(Integer roleId) {
        return authMapper.selectGetAssigned(roleId);
    }





    /**
     * 保存信息
     * @param listMap
     */
    @Override
    public void saveAuth(Map<String, List<Integer>> listMap) {
        List<Integer> list = listMap.get("roleId");
        Integer roleId = list.get(0);
        authMapper.deleteOldRelationShip(roleId);
        List<Integer> list1 = listMap.get("authIdArray");
        if (list1!=null && list1.size()>0){
            authMapper.insertNewRelationShip(roleId,list1);
        }

    }




    @Override
    public List<String> getAssignedAuthNameByAdminId(Integer adminId) {
        return authMapper.selectAssignedAuthNameByAdminId(adminId);
    }
}
